<?php
require_once('../lib/diy.php');

if (isset($_GET['logout'])) {
  session_destroy();
  redirect("/");
 }

$ini = parse_ini_file('../../.diycity.ini');

if ($_SESSION['admin'] == true || $_POST['pass'] == $ini['admin_password'])
  {
    require_once("../lib/model.php");
    if (!isset($_SESSION['admin']))
      $_SESSION['admin'] = true;

    $problems = new DiyModel('problems');
    $result = $problems->find('all', array('order' => 'id desc'));
    for($i=0; $i < sizeof($result); ++$i) {
      if (file_exists("../photos/{$result[$i]['id']}"))
	$result[$i]['img'] = true;
    }
    $smarty = new Smarty_Diycity();

    $smarty->assign('total', $result);
    $smarty->display('admin.tpl');
  }
 else
   {
     $smarty = new Smarty_Diycity();
     $smarty->display('admin_login.tpl');
   }
?>
